// index.js
const { getMockData } = require('../../utils/data.js')
Page({
  data: {
    lotteryTypes: ['双色球', '3D'],
    selectedType: '双色球',
    periods: [20, 50, 100],
    selectedPeriod: 20,
    type: '',
    period: 0,
    result: {}
  },
  // 当彩种选择改变时触发
  bindTypeChange: function(e) {
    this.setData({
      selectedType: this.data.lotteryTypes[e.detail.value]
    })
  },
  // 当期数选择改变时触发
  bindPeriodChange: function(e) {
    this.setData({
      selectedPeriod: this.data.periods[e.detail.value]
    })
  },
  // 点击统计按钮时触发
  onStatisticsTap: function() {
    this.loadResult(this.data.selectedType, this.data.selectedPeriod)
  },

  loadResult: function (type, period) {
    // 这里应该是从服务器获取数据，现在用模拟数据代替
    const mockData = getMockData(type, period)
    this.setData({ result: mockData })
  }
})
